﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CardLogistics.Web.Controls
{
    public partial class WebUserControl_Nav : System.Web.UI.UserControl
    {
        private static DataTable dt;
        protected string NavOne = "";//一级菜单
        protected string NavTwo = "";//二级菜单
        protected string NavDo = "";//当前操作

        protected void Page_Load(object sender, EventArgs e)
        {
            if (dt == null)
                dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select * from sys_menus ");
            GetNavInfo();
        }
        private void GetNavInfo()
        {
            string mid = Request.QueryString["mid"];

            if (!string.IsNullOrEmpty(mid))
            {
                DataRow[] drT = dt.Select(" MENUID='" + mid + "' ");
                if (drT.Length > 0)
                {
                    //NavTwo = "<li><a href=‘ListInfo.aspx?mid=" + drT[0]["menuid"].ToString() + "’>" + drT[0]["MENUNAME"].ToString() + "</a></li>";
                    if (drT[0]["URLWINFORMNAME"] != null && drT[0]["URLWINFORMNAME"].ToString() != "")
                    {
                        string ulStr = drT[0]["URLWINFORMNAME"].ToString().Split('/')[drT[0]["URLWINFORMNAME"].ToString().Split('/').Length - 1];
                        NavTwo = "<li><a href='" + ulStr + "?mid="+mid+"'>" + drT[0]["MENUNAME"].ToString() + "</a></li>";
                    }
                    else
                        NavTwo = "<li>" + drT[0]["MENUNAME"].ToString() + "</li>";

                    DataRow[] drO = dt.Select(" MENUID='" + drT[0]["PARENTID"].ToString() + "' ");
                    if (drO.Length > 0)
                    {
                       
                          
                            NavOne = "<li>" + drO[0]["MENUNAME"].ToString() + "</li>";
                    }
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["type"]))
            {
                string typeStr = Request.QueryString["type"];
                if (typeStr.ToLower() == "add")
                {
                    NavDo = "<li>新增</li>";
                }
                else if (typeStr.ToLower() == "edit")
                {
                    NavDo = "<li>修改</li>";
                }
                else if (typeStr.ToLower() == "detail")
                {
                    NavDo = "<li>详情</li>";
                }
            }
        }
    }
}